package cn.lijigou.shopping.views;

import cn.lijigou.shopping.DialogWidgetActivity;
import android.content.Context;
import android.os.Handler;
import android.os.Message;
import android.util.AttributeSet;
import android.util.Log;
import android.util.TypedValue;
import android.view.MotionEvent;
import android.widget.ScrollView;

 

public class WidgetScrollView extends android.widget.ScrollView{
	int item;
	int total;
	public static int shopindex=0;
	public WidgetScrollView(Context context, AttributeSet attrs, int defStyle) {
			super(context, attrs, defStyle);
			// TODO Auto-generated constructor stub
			item=(int)TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 30, this.getResources().getDisplayMetrics());
			total=(int)TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 150, this.getResources().getDisplayMetrics());
		}
	public WidgetScrollView(Context context, AttributeSet attrs) {
			super(context, attrs);
			// TODO Auto-generated constructor stub
			item=(int)TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 30, this.getResources().getDisplayMetrics());
		    total=(int)TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 150, this.getResources().getDisplayMetrics());
			
		}
    public WidgetScrollView(Context context) {
		super(context);
		item=(int)TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 30, this.getResources().getDisplayMetrics());
		total=(int)TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 150, this.getResources().getDisplayMetrics());
	}
 
	
	public Handler waitHander = new Handler(){
		@Override
		public void handleMessage(Message msg) {
			super.handleMessage(msg);
			
			smoothScrollTo(0,((getScrollY()/item))*item);
			shopindex=((getScrollY()/item));
			DialogWidgetActivity.Notify();
//			if(getScrollX()<=(ChoiceLocationActivity.setWidth/2)+10){
//				
//			}else if(getScrollX()>=(ChoiceLocationActivity.setWidth/2)+10&&(getScrollX()<=ChoiceLocationActivity.setWidth)){
//				smoothScrollTo(ChoiceLocationActivity.setWidth, 0);
//			}else if(getScrollX()>ChoiceLocationActivity.setWidth&&(getScrollX()<=ChoiceLocationActivity.setWidth+(ChoiceLocationActivity.setWidth/2)+10)){
//				smoothScrollTo(ChoiceLocationActivity.setWidth, 0);
//			}else{
//				smoothScrollTo(ChoiceLocationActivity.width+ChoiceLocationActivity.setWidth, 0);
//			}
			
	}
            
	};
    
    
	 
	  @Override
      public void fling(int velocityY) {
          super.fling(velocityY /4);
         
      }

	@Override
	public boolean onTouchEvent(MotionEvent ev) {
		switch (ev.getAction()) {
			case MotionEvent.ACTION_MOVE:
				break;
			case MotionEvent.ACTION_DOWN:
				
				break;
			case MotionEvent.ACTION_UP:
				waitHander.sendEmptyMessageDelayed(1, 50);
				break;
		}
			return super.onTouchEvent(ev);
	}
	@Override
	public void scrollTo(int x, int y) {
		// TODO Auto-generated method stub
			super.scrollTo(x, y);
	}
}
